package com.freshcity.component.guide
{
	import com.freshcity.manager.LayerManager;
	import com.pblabs.core.IPBManager;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.utils.*;
	
	public class GuideArrowManager implements IPBManager
	{
		public static const Dir_R:int=5; //向右
		
		public static const Dir_L:int=6; //向左
		
		public static const Dir_T:int=7; //向上
		
		public static const Dir_B:int=8; //向下
		
		private static var _guideArrow:GuideArrow;
		
		private static var _dialogArrow:GuideArrow;
		
		private static var _timerKey:uint;
		
		private static var _onDelay:Function;
		
		private static var _thumbParent:Sprite;
		
		[Inject]
		public var layerManager:LayerManager;		
		
		public function destroy():void
		{
			// TODO Auto Generated method stub
			
		}
		
		public function initialize():void
		{
			_guideArrow = new GuideArrow();
			_dialogArrow = new GuideArrow();
			_thumbParent = new Sprite();
		}
		
		public static function get guideArrow():GuideArrow
		{
			return _guideArrow;
		}
		
		public static function get dialogArrow():GuideArrow
		{
			return _dialogArrow;
		}
		
		public static function getGuideArrow(dir:int, fun:Function=null, timeout:int=0):GuideArrow
		{
			hideGuideArrow();
			_guideArrow.updateDir(dir);
			if (timeout > 0) 
			{
				_timerKey = setTimeout(onTimerOut, timeout);
			}
			if (fun != null) 
			{
				_onDelay = fun;
			}
			return _guideArrow;
		}
		
		public static function getDialogGuideArrow(arg1:int):GuideArrow
		{
			hideDialogArrow();
			_dialogArrow.updateDir(arg1);
			return _dialogArrow;
		}
		
		public static function showGuideArrowAtLayer(arg1:DisplayObjectContainer, arg2:int, arg3:int, arg4:int, arg5:Function=null, arg6:int=20000):void
		{
			var loc1:*;
			(loc1 = getGuideArrow(arg4, arg5, arg6)).x = arg2;
			loc1.y = arg3;
			arg1.addChild(loc1);
		}
		
		private static function onTimerOut():void
		{
			if (_onDelay != null) 
			{
				_onDelay();
			}
			hideGuideArrow();
		}
		
		private static function clearTimer():void
		{
			clearTimeout(_timerKey);
			_onDelay = null;
			
		}
		
		public static function hideGuideArrow():void
		{
			clearTimer();
			if (_guideArrow.parent != _thumbParent) 
			{
				_thumbParent.addChild(_guideArrow);
				_guideArrow.dispose();
			}
		}
		
		public static function hideDialogArrow():void
		{
			if (_dialogArrow.parent != _thumbParent) 
			{
				_thumbParent.addChild(_dialogArrow);
				_dialogArrow.dispose();
			}
		}
	}
}